package org.zhuxian.cn.controller;

import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zhuxian.cn.result.JsonResult;
import org.zhuxian.cn.service.EquipmentBuildsLikeService;

@RestController
@RequestMapping("/api/equipment-builds/like")
@Api(tags = "配装点赞接口", description = "提供配装点赞相关的接口")
public class EquipmentBuildsLikeController {

    @Autowired
    private EquipmentBuildsLikeService equipmentBuildsLikeService;

    @PostMapping("/{buildId}")
    @Operation(summary = "点赞配装", description = "用户对指定配装进行点赞")
    public JsonResult<Boolean> like(
            @Parameter(description = "配装ID") @PathVariable Integer buildId,
            @Parameter(description = "用户ID") @RequestParam Long userId) {
        boolean success = equipmentBuildsLikeService.like(buildId, userId);
        return new JsonResult(200, "OK", success);
    }

    @DeleteMapping("/{buildId}")
    @Operation(summary = "取消点赞", description = "用户取消对指定配装的点赞")
    public JsonResult<Boolean> unlike(
            @Parameter(description = "配装ID") @PathVariable Integer buildId,
            @Parameter(description = "用户ID") @RequestParam Long userId) {
        boolean success = equipmentBuildsLikeService.unlike(buildId, userId);
        return new JsonResult(200, "OK", success);
    }

    @GetMapping("/{buildId}/status")
    @Operation(summary = "查询点赞状态", description = "查询用户是否对指定配装点赞")
    public JsonResult<Boolean> hasLiked(
            @Parameter(description = "配装ID") @PathVariable Integer buildId,
            @Parameter(description = "用户ID") @RequestParam Long userId) {
        boolean hasLiked = equipmentBuildsLikeService.hasLiked(buildId, userId);
        return new JsonResult(200, "OK", hasLiked);
    }

    @GetMapping("/{buildId}/count")
    @Operation(summary = "获取点赞数", description = "获取指定配装的点赞数量")
    public JsonResult<Integer> getLikeCount(
            @Parameter(description = "配装ID") @PathVariable Integer buildId) {
        Integer count = equipmentBuildsLikeService.getLikeCount(buildId);
        return new JsonResult(200, "OK", count);
    }
}